<?

//Data loading
$title='DAFTAR FAKTUR PAJAK STANDAR & SEDERHANA';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
//else $perush = GetCompany (GetOfficeID());
else $perush = "PT. MASAJI PRAYASA CARGO";

$page   = 'PAGE';
$TableName = "view_faktur_no";
$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = ReportList ("", "", "");
if ($Result) $pdf->ReportTable($Result);
$pdf->Output();

function ReportList ($Space, $Index, $ParentID) {
                  global $RS,$Index,$TableName;
                  $DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
                        if (!$Index) $Index = 0;

      $SQL = "SELECT *,jumlah*(SELECT rate FROM ais_kurspjk WHERE ais_kurspjk.tglbkt<=$TableName.tglbkt AND ais_kurspjk.curr=$TableName.curr ORDER BY ais_kurspjk.tglbkt DESC LIMIT 1) as rupiah, date_format(tglbkt,'%d/%m/%y') as tgl
                FROM $TableName
                WHERE skada like '".GetPPNSkada()."'
             ";
      list($day,$month,$year) = explode("/",GetParam("fromDate",""));
      $FDate = "$year-$month-$day";
      list($day,$month,$year) = explode("/",GetParam("toDate",""));
      $TDate = "$year-$month-$day";

      $SQL .= " AND tglbkt >= '$FDate' AND tglbkt<='$TDate' ";
      $SQL .= " ORDER BY vat, nobkt, tglbkt";

      $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
      return $MyResult;
}

class PDFReport extends PDF {

        function Header() {
                global $title,$perush,$page,$DEFINE_FONT;
                if ($DEFINE_FONT==0) {
                        $this->AddFont('arialn','','arialn.php');
                        $DEFINE_FONT=1;
                }
                $this->SetFont('arialn','',10);
        $this->Cell(195,5,$perush,0,1,'C',0);
        $this->Cell(195,5,$title,0,1,'C',0);
        $SystemDate = date("d/m/Y");
        $this->Cell(195,5,"PERIODE: ".GetParam("fromDate","")." S/D ".GetParam("toDate",""),0,1,'C',0);
        $this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
//        $this->Line(10,30,205,30);
  //      $this->Ln();
        //Header

        //Column widths
        $w=array(15,30,60,20,10,15,20,25);
        $this->SetFont('arialn','',9);
        $this->Cell($w[0],7,"TANGGAL","TB",0,'C',0);
        $this->Cell($w[1],7,"NO FAKTUR","TB",0,'C',0);
        $this->Cell($w[2],7,"CUSTOMER","TB",0,'C',0);
        $this->Cell($w[3],7,"NPWP","TB",0,'L',0);
        $this->Cell($w[4],7,"CURR","TB",0,'C',0);
        $this->Cell($w[5],7,"PAJAK","TB",0,'C',0);
        $this->Cell($w[6],7,"RUPIAH","TB",0,'C',0);
        $this->Cell($w[7],7,"NO. BUKTI","TB",0,'C',0);
        $this->Ln();
        }

        function ReportTable($Result) {
            //Column widths
            global $DBConnection;
                $w= array(15,30,60,20,10,15,20,25);
            //Data
                $SQL = "SELECT taxprefix FROM tblprofile ";
                $TaxPrefix = $DBConnection->dbc->get_var($SQL);

            $ShowSubtotalSederhana = 1;
            foreach($Result as $row)
            {

//      if ((substr($row["vat"],0,strlen($TaxPrefix))==$TaxPrefix) && $ShowSubtotalSederhana==1 ) {
      if ((strlen($row["vat"])==19) && $ShowSubtotalSederhana==1 ) {

                      $this->Ln();
                      $this->Cell($w[0]+$w[1],5,"",0,0,'L');
                      $this->Cell($w[2],5,"Total Faktur Pajak Sederhana : ",0,0,'L');
                      $this->Cell(3,5,":",0,0,'L');
                      $this->Cell($w[3],5,FormatNumber($Subtotal),"TB",0,'R');
                      $this->Ln();
                      $this->Ln();
                      $ShowSubtotalSederhana = 0;
                      $SubtotalSederhana = $Subtotal;
                      $Subtotal = 0;

      }
                        $Subtotal = $Subtotal + $row["rupiah"];

                        $this->Cell($w[0],5,$row["tgl"],0,0,'C');
                        $this->Cell($w[1],5,$row["vat"],0,0,'L');
                        $this->Cell($w[2],5,$row["debnam"],0,0,'L');
                        $this->Cell($w[3],5,$row["npwp"],0,0,'L');
                        $this->Cell($w[4],5,$row["curr"],0,0,'C');
                        $this->Cell($w[5],5,FormatNumber($row["jumlah"]),0,0,'R');
                        $this->Cell($w[6],5,FormatNumber($row["rupiah"]),0,0,'R');
                        $this->Cell($w[7],5,$row["nobkt"],0,0,'C');
                        $this->Ln();
                        $LastTaxNumber = substr($row["vat"],0,3);
            }
      $this->Ln();
      $this->Cell($w[0]+$w[1],5,"",0,0,'L');
      $this->Cell($w[2],5,"Total Faktur Pajak Standar",0,0,'L');
      $this->Cell(3,5,":",0,0,'L');
      $this->Cell($w[3],5,FormatNumber($Subtotal),"TB",0,'R');
      $this->Ln();
            $GrandTotal = $Subtotal + $SubtotalSederhana;
      $this->Cell($w[0]+$w[1],5,"",0,0,'L');
      $this->Cell($w[2],5,"Total Seluruh",0,0,'L');
      $this->Cell(3,5,":",0,0,'L');
      $this->Cell($w[3],5,FormatNumber($GrandTotal),"TB",0,'R');
      $this->Ln();
      $this->Ln();
      $this->Ln();
      $this->Ln();
                        $this->Cell($w[0]+$w[1],5,"Pemeriksa",0,0,'C');
      $this->Ln();
      $this->Ln();
      $this->Ln();
      $this->Ln();
                        $this->Cell($w[0]+$w[1],5,"( ......................................... )",0,0,'C');
            //Closure line
            //$this->Cell(array_sum($w),0,'','T');
        }

        function Footer() {
            //Closure line
//            $this->Cell(195,0,'','T');
        }

}


?>
